<?php

/**
 * This is the model class for table "payment_processor".
 *
 * The followings are the available columns in table 'payment_processor':
 * @property string $payment_processors_id
 * @property string $code
 * @property string $name
 * @property string $status
 * @property string $create_date
 * @property string $create_by
 * @property string $update_date
 * @property string $update_by
 * @property string $enable_for_withdraw
 * @property double $charge
 *
 * The followings are the available model relations:
 * @property MemberAccount[] $memberAccounts
 * @property PaymentProcessorsSetting[] $paymentProcessorsSettings
 * @property TransactionHistory[] $transactionHistories
 */
class PaymentProcessor extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return PaymentProcessor the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'payment_processor';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name, code', 'required'),
            array('code, name', 'length', 'max' => 255),
            array('status', 'length', 'max' => 45),
            array('enable_for_withdraw', 'length', 'max' => 1),
            array('charge', 'numerical'),
            array('create_by, update_by', 'length', 'max' => 10),
            array('create_date, update_date', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('payment_processors_id, code, name, status, create_date, create_by, update_date, update_by', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'memberAccounts' => array(self::HAS_MANY, 'MemberAccount', 'payment_processors_id'),
            'paymentProcessorsSettings' => array(self::HAS_MANY, 'PaymentProcessorsSetting', 'payment_processors_id'),
            'transactionHistories' => array(self::HAS_MANY, 'TransactionHistory', 'payment_processors_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'payment_processors_id' => 'Payment Processors ID',
            'code' => 'Payment Processor Code',
            'name' => 'Payment Processor Name',
            'status' => 'Active',
            'enable_for_withdraw' => 'Active for withdraw',
            'charge' => 'Charge Fee(%)',
            'create_date' => 'Create Date',
            'create_by' => 'Create By',
            'update_date' => 'Update Date',
            'update_by' => 'Update By',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('payment_processors_id', $this->payment_processors_id, true);
        $criteria->compare('code', $this->code, true);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('status', $this->status, true);
        $criteria->compare('enable_for_withdraw', $this->enable_for_withdraw, true);
        $criteria->compare('charge', $this->charge);
        $criteria->compare('create_date', $this->create_date, true);
        $criteria->compare('create_by', $this->create_by, true);
        $criteria->compare('update_date', $this->update_date, true);
        $criteria->compare('update_by', $this->update_by, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}